﻿using System;
using System.Collections.ObjectModel;
using System.Linq;
using FileSquirrel.Logic;
using FSquirrel.Design;
using FSquirrel.Properties;

namespace FSquirrel.Model
{
    public class ShowListModel
    {
        public ShowListModel()
        {
            Reader._libName = Settings.Default.LibraryName;
            Reader._libdir = Settings.Default.LibraryDir;
        }



        private ObservableCollection<FileRowModel> _libshows;

        public ObservableCollection<FileRowModel> LibShows
        {
            get
            {
                if (_libshows == null || _libshows.Count() == 0)
                {
                    int _icount = 0;
                    _libshows = new ObservableCollection<FileRowModel>();
                    foreach (var row in Reader.GlobalLibrary._Files.OrderBy(library => library.DateModified))
                    {
                        var frm = new FileRowModel();

                        frm.Category = row.Category;
                        frm.DateModified = row.DateModified;
                        frm.Duration = row.IsDurationNull() ? new TimeSpan() : row.Duration;
                        frm.EpisodeNr = row.IsEpisodeNrNull() ? string.Empty : row.EpisodeNr;
                        frm.Extension = row.Extension;
                        frm.Name = row.Name;
                        frm.Path = row.Path;
                        frm.Resolution = row.IsResolutionNull() ? string.Empty : row.Resolution;
                        frm.Season = row.IsSeasonNull() ? string.Empty : row.Season;
                        frm.Show = row.IsShowNull() ? string.Empty : row.Show;
                        frm.Size = row.Size;
                        _libshows.Add(frm);
                    }
                }
                return _libshows;
            }
            set { _libshows = value; }
        }
    }
}